<template>
    <div style="width: 100%;height: 100%;position: relative">
        <Spin size="large" fix v-if="Loading"></Spin>
        <Form :label-width="180" ref="formValidate" :model="formValidate" id="form"
              :rules="ruleValidate">
            <table>
                <tr>
                    <td colspan="2">
                        <Form-item label="家庭人员信息:">
                            <span style="padding-right: 20px">{{memberInformation}}</span>
                            <font v-if="information.includes('不符合')" color="red"
                                  style="font-size: 16px">{{information}}</font>
                            <font v-else color="green" style="font-size: 16px">{{information}}</font>
                        </Form-item>
                    </td>
                </tr>
                <tr>
                    <td>
                        <Form-item label="家庭月基础收入金额:" prop="ssca0044">
                            <Input v-model="formValidate.ssca0044" placeholder="请输入家庭月基础收入金额" :disabled="disabled"/>
                        </Form-item>
                    </td>
                    <td>
                        <Form-item label="家庭月赡抚养费金额:" prop="ssca0045">
                            <Input v-model="formValidate.ssca0045" placeholder="请输入家庭月赡抚养费金额" :disabled="disabled"/>
                        </Form-item>
                    </td>
                </tr>
                <tr>
                    <td style="width: 50%">
                        <Form-item label="家庭月财产收入金额:" prop="ssca0046">
                            <Input v-model="formValidate.ssca0046" placeholder="请输入家庭月财产收入金额" :disabled="disabled"/>
                        </Form-item>
                    </td>
                    <td>
                        <Form-item label="家庭月基础支出金额:" prop="ssca0047">
                            <Input v-model="formValidate.ssca0047" placeholder="请输入家庭月基础支出金额" :disabled="disabled"/>
                        </Form-item>
                    </td>
                </tr>
                <tr>
                    <td style="width: 50%">
                        <Form-item label="核减金额:" prop="ssca0113">
                            <Input v-model="formValidate.ssca0113" placeholder="请输入核减金额" :disabled="disabled"/>
                        </Form-item>
                    </td>
                    <td style="width: 50%">
                        <Form-item label="家庭月总收入金额(核减并扣除家庭支出):" prop="ssca0049">
                            <Input v-model="formValidate.ssca0049" placeholder="请输入家庭月总收入金额" :disabled="disabled"/>
                        </Form-item>
                    </td>
                </tr>
                <tr>
                    <td>
                        <Form-item label="家庭人口数:" prop="ssca0051">
                            <Input v-model="formValidate.ssca0051" placeholder="请输入家庭人口数" :disabled="disabled"/>
                        </Form-item>
                    </td>
                    <td>
                        <Form-item label="保障人口数:" prop="ssca0052">
                            <Input v-model="formValidate.ssca0052" placeholder="请输入保障人口数" :disabled="disabled"/>
                        </Form-item>
                    </td>
                </tr>
                <tr v-if="formValidate.ssca0002=='100'||formValidate.ssca0002=='200'||formValidate.ssca0002=='102'||formValidate.ssca0002=='202'">
                    <td>
                        <Form-item label="差额保障金额:" prop="ssca0004">
                            <Input v-model="formValidate.ssca0004" placeholder="请输入差额保障金额" :disabled="disabled"/>
                        </Form-item>
                    </td>
                    <td style="width: 50%">
                        <Form-item label="分类救助上浮总金额:" prop="ssca0025">
                            <Input v-model="formValidate.ssca0025" placeholder="请输入分类救助上浮总金额" :disabled="disabled"/>
                        </Form-item>
                    </td>

                </tr>
                <tr>
                    <td style="width: 50%">
                        <Form-item label="保障标准:" prop="ssca0042">
                            <Input v-model="formValidate.ssca0042" placeholder="请输入保障标准" :disabled="disabled"/>
                        </Form-item>
                    </td>
                    <td style="width: 50%">

                        <Form-item label="总保障金额:" prop="ssca0026">
                            <Input v-model="formValidate.ssca0026" placeholder="请输入总保障金额" :disabled="disabled"/>
                        </Form-item>
                        <div style="color:red;margin-left: 180px">
                            <span v-if="formValidate.ssca0002=='100'||formValidate.ssca0002=='200'||formValidate.ssca0002=='102'||formValidate.ssca0002=='202'">
                                （总保障金额=差额保障金额+分类救助上浮总金额，不包括高龄补贴总金额）</span>
                            <span v-else>（总保障金额=保障人口数*保障标准，不包括高龄补贴总金额）</span>
                        </div>
                    </td>

                </tr>
                <tr>
                    <td>
                        <Form-item label="高龄补贴总金额:" prop="ssca0065">
                            <Input v-model="formValidate.ssca0065" placeholder="请输入高龄补贴总金额" :disabled="disabled"/>
                        </Form-item>
                    </td>
                    <td style="width: 50%">
                        <Form-item label="致贫原因:" prop="ssca0013">
                            <c-dict-select v-model="formValidate.ssca0013" dictCode="poorreason" :width="300"/>

                        </Form-item>
                    </td>

                </tr>
                <tr v-if="formValidate.ssca0002!='203'">
                    <td style="width: 50%">
                        <Form-item label="是否容缺受理:" prop="ssca0097">
                            <c-dict-select v-model="formValidate.ssca0097" dictCode="yesorno" :width="300"/>

                        </Form-item>
                    </td>
                    <td>
                        <Form-item label="是否民主评议:" prop="ssca0089">
                            <c-dict-select v-model="formValidate.ssca0089" dictCode="yesorno" :width="300"
                                           :disabled="ssca0089Disabled"/>
                        </Form-item>
                    </td>
                </tr>
                <tr>
                    <td style="width: 50%">
                        <Form-item label="申请时间:" prop="ssca0003">
                            <DatePicker type="date" v-model="formValidate.ssca0003" placeholder="请选择申请时间"
                                        class="time" :editable="false"></DatePicker>
                        </Form-item>
                    </td>
                    <td v-if="formValidate.ssca0002!='203'">
                        <Form-item label="是否提取使用最新核对报告:" prop="ssca0086">
                            <c-dict-select v-model="formValidate.ssca0086" dictCode="yesorno" :width="300"/>
                        </Form-item>
                    </td>

                </tr>
                <tr>
                    <td colspan="2">
                        <Form-item label="救助申请理由:" prop="ssca0008">
                            <c-text-area v-model="formValidate.ssca0008" :max-length="100" :row=3 width="890"
                                         placeholder="请填写救助申请理由"/>
                        </Form-item>
                    </td>
                </tr>
                <!--<tr>-->
                <!--<td style="width: 50%">-->
                <!--<Form-item label="不予受理原因:" prop="ssca0078">-->
                <!--<dictSelect :sel_val='formValidate.ssca0078' dictCode="inadmissibility" style="width: 40%"-->
                <!--:bindData.sync="formValidate.ssca0078" clearable/>-->
                <!--</Form-item>-->
                <!--</td>-->
                <!--<td>-->
                <!--<Form-item label="不予受理原因说明:" prop="ssca0031">-->
                <!--<Input v-model="formValidate.ssca0031" type="textarea"-->
                <!--:autosize="{minRows: 1,maxRows: 8}" placeholder="请填写不予受理原因说明"/>-->
                <!--</Form-item>-->
                <!--</td>-->
                <!--</tr>-->
            </table>
        </Form>

        <div id="buttondiv">
            <Button @click="prevStep"> 上一步</Button>
            <Tooltip placement="top">
                <Button type="error" @click="printSs00011" style="margin-left: 10px">事前查验结果打印</Button>
                <div slot="content">
                    <p>请打印查验结果后，进行提交申请 !</p>
                </div>
            </Tooltip>
            <Button type="primary" @click="nextStep1" :disabled="submitDisabled" style="margin-left: 10px">提交申请</Button>
            <!--<Button type="error" @click="nextStep2" style="margin-left: 10px">不予受理</Button>-->
        </div>
        <ss00011-print-modal ref="printModal" @changeSubmit="changeSubmit"/>
    </div>
</template>

<script>
    import {getAction, postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import '@/views/common/css/common.css';
    import Ss00011PrintModal from './modules/Ss00011PrintModal'


    export default {
        name: "application2",
        mixins: [CommonMixin],
        components: {
            Ss00011PrintModal,
        },
        data() {
            return {
                ssca0089Disabled: false,
                modalSs00011: false,
                submitDisabled: true,
                url: {
                    tab12Infor: "/api/ac/subsistence/ss12001Service/createTab12Infor",
                    tab12Submit: "/api/ac/subsistence/ss12001Service/createTab12Submit",
                },
                Loading: false,
                familyInfo: {},
                formValidate: {},
                disabled: true,
                information: "",
                memberInformation: "",
                ruleValidate: {
                    ssca0044: [
                        {required: true, message: '家庭月基础收入金额不能为空!', trigger: 'blur', type: "number"}
                    ],
                    ssca0045: [
                        {required: true, message: '家庭月赡抚养费金额不能为空!', trigger: 'blur', type: "number"}
                    ],
                    ssca0046: [
                        {required: true, message: '家庭月财产收入金额不能为空!', trigger: 'blur', type: "number"}
                    ],
                    ssca0047: [
                        {required: true, message: '家庭月基础支出金额不能为空!', trigger: 'blur', type: "number"}
                    ],
                    ssca0049: [
                        {required: true, message: '家庭月总收入金额不能为空!', trigger: 'blur', type: "number"}
                    ],
                    ssca0051: [
                        {required: true, message: '家庭人口数不能为空!', trigger: 'blur', type: "number"}
                    ],
                    ssca0042: [
                        {required: true, message: '保障标准不能为空!', trigger: 'blur', type: "number"}
                    ],
                    ssca0052: [
                        {required: true, message: '保障人口数不能为空!', trigger: 'blur', type: "number"}
                    ],
                    ssca0025: [
                        {required: true, message: '分类救助上浮总金额不能为空！', trigger: 'blur', type: "number"}
                    ],
                    ssca0004: [
                        {required: true, message: '差额保障金额不能为空！', trigger: 'blur', type: "number"}
                    ],
                    ssca0026: [
                        {required: true, message: '总保障金额不能为空！', trigger: 'blur', type: "number"}
                    ],
                    ssca0065: [
                        {required: true, message: '高龄补贴总金额不能为空！', trigger: 'blur', type: "number"}
                    ],
                    ssca0013: [
                        {required: true, message: '请选择致贫原因！', trigger: 'change'}
                    ],
                    ssca0086: [
                        {required: true, message: '请选择是否提取使用最新核对报告！', trigger: 'change'}
                    ],
                    ssca0003: [
                        {required: true, message: '申请时间不能为空！', trigger: 'change', type: "date"}
                    ],
                    ssca0008: [
                        {required: true, message: '救助申请理由不能为空！', trigger: 'blur'}
                    ],
                    ssca0078: [
                        {required: false, message: '不予受理原因不能为空！', trigger: 'blur'}
                    ],
                    ssca0031: [
                        {required: false, message: '不予受理原因说明不能为空！', trigger: 'blur'}
                    ],
                    ssca0089: [
                        {required: true, message: '请选择是否民主评议！', trigger: 'change'}
                    ],
                    ssca0097: [
                        {required: true, message: '请选择是否容缺受理！', trigger: 'change'}
                    ],
                },

            }
        },
        methods: {
            prevStep() {
                this.$emit('prevStep');
            },
            printSs00011() {
                this.$refs.printModal.edit(this.familyInfo.ss12001Id);
            },
            changeSubmit() {
                this.submitDisabled = false
            },
            //提交申请
            nextStep1() {
                //打印查验结果方可提交申请
                this.ruleValidate.ssca0003[0].required = true;
                this.ruleValidate.ssca0008[0].required = true;
                this.ruleValidate.ssca0078[0].required = false;
                this.ruleValidate.ssca0031[0].required = false;
                this.formValidate.ssca0075 = "0";
                this.tab12Submit();
            },
            //不予受理
            nextStep2() {
                this.ruleValidate.ssca0003[0].required = false;
                this.ruleValidate.ssca0008[0].required = false;
                this.ruleValidate.ssca0078[0].required = true;
                this.ruleValidate.ssca0031[0].required = true;
                this.formValidate.ssca0075 = "1";
                this.tab12Submit();
            },

            tab12Submit() {
                this.Loading = true;
                var that = this;
                this.$refs['formValidate'].validate((valid) => {
                    if (valid) {
                        postAction(that.url.tab12Submit, this.formValidate).then((res) => {
                            if (res.data.errcode == 0) {
                                that.$Message.success("提交申请成功！");
                                that.$emit('finish');
                            } else {
                                that.$Message.error(res.data.errmsg);
                            }
                        }).finally(() => {
                            that.Loading = false;
                        });
                    } else {
                        that.Loading = false;
                    }
                })
            },

            getFamilyInfor() {
                this.familyInfo = this.$parent.familyInfo;
            },

            getTab12Infor() {
                var that = this;
                postAction(that.url.tab12Infor, {ss12001Id: this.familyInfo.ss12001Id}).then((res) => {
                    if (res.data.errcode == 0) {
                        that.formValidate = res.data.data.ss12001;
                        if (that.formValidate.ssca0003) {
                            this.$set(this.formValidate, "ssca0003", this.DateFormat(that.formValidate.ssca0003, 'YYYY-MM-DD'));
                        } else {
                            this.$set(this.formValidate, "ssca0003", "");
                        }
                        that.information = res.data.data.information;
                        that.memberInformation = res.data.data.memberInformation;
                    } else {
                        that.$Message.error(res.data.errmsg);
                    }
                }).finally(() => {
                    that.Loading = false;
                });
            }
        },
        watch: {
            "formValidate.ssca0097": function (e) {
                let that = this;
                let value = that.formValidate.ssca0097;
                if (value == '1') {
                    that.ssca0089Disabled = true;
                    that.formValidate.ssca0089 = '1';
                } else {
                    that.ssca0089Disabled = false;
                }
            }
        },
        created() {
            this.Loading = true;
            this.getFamilyInfor();
            this.getTab12Infor();
        }
    }
</script>

<style scoped src="@/views/common/css/application12.css">

</style>
